package com.dyzx.hbb.modules.fcxs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.modules.fcxs.entity.FcxsDiscount;
import com.dyzx.hbb.modules.fcxs.entity.FcxsFinancial;
import com.dyzx.hbb.modules.fcxs.service.FcxsFinancialService;
import com.dyzx.hbb.modules.fcxs.mapper.FcxsFinancialMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author Administrator
* @description 针对表【fcxs_financial(收支表)】的数据库操作Service实现
* @createDate 2025-05-17 20:53:29
*/
@Service
public class FcxsFinancialServiceImpl extends ServiceImpl<FcxsFinancialMapper, FcxsFinancial>
    implements FcxsFinancialService{

    @Override
    public List<Map<String, Object>> findByOrderIdList(Long id) {
        return this.listMaps(queryInfoWrapper().eq(FcxsFinancial::getOrderId, id));
    }
    protected MyLambdaQueryWrapper<FcxsFinancial> queryInfoWrapper() {
        MyLambdaQueryWrapper<FcxsFinancial> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(FcxsFinancial::getId)
                .select(FcxsFinancial::getOrderId)
                .fcxsOrderNo(FcxsFinancial::getOrderId).as("order_no")
                .select(FcxsFinancial::getType)
                .select(FcxsFinancial::getCategory)
                .select(FcxsFinancial::getAmt)
                .select(FcxsFinancial::getPayMode)
                .select(FcxsFinancial::getImage)
                .imageUrls(FcxsFinancial::getImage).as("image_url")
                .select(FcxsFinancial::getBillType)
                .select(FcxsFinancial::getRemark)
                .select(FcxsFinancial::getStatus)
                .select(FcxsFinancial::getCreateDate)
                .select(FcxsFinancial::getUpdateDate)
                .organName(FcxsFinancial::getOrganId).as("organ_name")
                .userName(FcxsFinancial::getOperatorId).as("operator_name");
        return queryWrapper;
    }
    @Override
    public long findByOrderIdTotal(Long orderId) {
        MyLambdaQueryWrapper<FcxsFinancial> queryWrapper = queryInfoWrapper();
        queryWrapper.sum(FcxsFinancial::getAmt).as("amt").eq(FcxsFinancial::getOrderId, orderId);
        FcxsFinancial one = this.getOne(queryWrapper);
        return one != null ? one.getAmt() : 0;
    }
}




